package com.atguigu.bigdata.scala.mytest.chapter07


object Test_WordCount2 {
  def main(args: Array[String]): Unit = {
    val list = List(
      ("hello", 4),
      ("hello spark", 3),
      ("hello spark scala", 2),
      ("hello spark scala hive", 1)
    )

    val str: List[String] = list.map(t => (t._1+" ") * t._2)
    println(str)

    val strings: List[String] = str.flatMap(w =>w.split(" "))
    println(strings)

    val map1: Map[String, List[String]] = strings.groupBy(w => w)
    println(map1)

    val stringToInt: Map[String, Int] = map1.map(w => (w._1,w._2.size))
    println(stringToInt)

    val tuples: List[(String, Int)] = stringToInt.toList.sortBy(w => w._2)(Ordering.Int.reverse)
    println(tuples)

    val tuples1: List[(String, Int)] = tuples.take(3)
    println(tuples1)
  }
}
